package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.anno.Logs;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/7 20:51
 */
@Slf4j
@RestController
@RequestMapping("/courses")
@SuppressWarnings("all")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping
    public Result getCoursePage(CourseDTO courseDTO) {
        log.info("getCoursePage: {}", courseDTO);
        return Result.success(courseService.Page(courseDTO));
    }

    @Logs("添加课程")
    @PostMapping
    public Result addCourse(@RequestBody Course course) {
        log.info("addCourse: {}", course);
        courseService.add(course);
        return Result.success();
    }

    @Logs("删除课程")
    @DeleteMapping("/{id}")
    public Result deleteCourse(@PathVariable Integer id) {
        log.info("deleteCourse: {}", id);
        courseService.delete(id);
        return Result.success();
    }

    @Logs("根据ID查询课程详情")
    @GetMapping("/{id}")
    public Result getCourse(@PathVariable Integer id) {
        log.info("getCourse: {}", id);
        return Result.success(courseService.get(id));
    }

    @Logs("更新课程")
    @PutMapping
    public Result updateCourse(@RequestBody Course course) {
        log.info("updateCourse: {}", course);
        courseService.update(course);
        return Result.success();
    }

    @GetMapping("/list")
    public Result listCourse() {
        log.info("listCourse");
        return Result.success(courseService.list());
    }

    @Logs("根据课程名称查询课程")
    @GetMapping("/subject/{subject}")
    public Result listSubject(@PathVariable String subject) {
        log.info("listSubject: {}", subject);
        return Result.success(courseService.listSubject(subject));
    }
}
